home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / lists / mint / l_1199 / 996 < prev    next >
Encoding:
Internet Message Format  |  1994-08-27  |  4.7 KB

  1. From: Stephen Usher <Stephen.Usher@earth.ox.ac.uk>
  2. Subject: Load average patch for MiNT 1.09.
  3. Date: Fri, 11 Feb 1994 08:12:04 +0000 (GMT)
  4. Mime-Version: 1.0
  5.  
  6. Here's a patch for MiNT 1.09 which gives it an uptime counter and set of
  7. load averages accessed by a system call Suptime().
  8.  
  9. BUGS
  10.  
  11.     The uptime and load average code uses the Vertical Blank Interrupt
  12.     to update its values and assumes that the interrupt will happen
  13.     60 times per second. This is a false assumption on PAL STs running
  14.     in either ST Low or ST Medium resolutions in which case the uptime
  15.     clock will run slow.
  16.  
  17. Anyway, here's the patch, it doesn't include a patch for the makefile as my
  18. makefile is hacked to death.
  19.  
  20. Steve
  21.  
  22. --8<-- Cut -- Here --8<--
  23. *** ../mint.src/loadave.h    Thu Feb 10 20:38:02 1994
  24. --- loadave.h    Thu Feb 10 20:09:46 1994
  25. ***************
  26. *** 0 ****
  27. --- 1,11 ----
  28. + #define TICKS_PER_TOCK        60
  29. + #define TOCKS_PER_SECOND    1
  30. + #define SAMPS_PER_MIN    12
  31. + #define SAMPS_PER_5MIN    SAMPS_PER_MIN * 5
  32. + #define SAMPS_PER_15MIN    SAMPS_PER_MIN * 15
  33. + #define LOAD_SCALE 2048
  34. + extern unsigned long uptime;
  35. + extern unsigned long avenrun[3];
  36. *** ../mint.src/dos.c    Thu Feb 10 20:06:48 1994
  37. --- dos.c    Thu Feb 10 20:40:04 1994
  38. ***************
  39. *** 455,460 ****
  40. --- 455,480 ----
  41.   }
  42.   
  43.   /*
  44. +  * Suptime: get time in seconds since boot and current load averages from
  45. +  * kernel.
  46. +  */
  47. + #include "loadave.h"
  48. + long ARGS_ON_STACK
  49. + s_uptime(cur_uptime, loadaverage)
  50. +     unsigned long *cur_uptime;
  51. +     unsigned long loadaverage[3];
  52. + {
  53. +     *cur_uptime = uptime;
  54. +     loadaverage[0] = avenrun[0];
  55. +     loadaverage[1] = avenrun[1];
  56. +     loadaverage[2] = avenrun[2];
  57. +     return 0;
  58. + }
  59. + /*
  60.    * routine for initializing DOS
  61.    *
  62.    * NOTE: before adding new functions, check the definition of
  63. ***************
  64. *** 588,591 ****
  65. --- 608,612 ----
  66.       dos_tab[0x13a] = p_waitpid;
  67.       dos_tab[0x13b] = d_getcwd;
  68.       dos_tab[0x13c] = s_alert;
  69. +     dos_tab[0x13d] = s_uptime;
  70.   }
  71. *** ../mint.src/proc.c    Thu Feb 10 20:07:00 1994
  72. --- proc.c    Thu Feb 10 20:09:14 1994
  73. ***************
  74. *** 642,647 ****
  75. --- 642,659 ----
  76.   #define qname(x) ((x >= 0 && x < NUM_QUEUES) ? qstring[x] : "unkn")
  77.   #endif
  78.   
  79. + #include "loadave.h"
  80. + unsigned long uptime = 0;
  81. + unsigned long avenrun[3] = {0,0,0};
  82. + unsigned int tick = 0;
  83. + unsigned long number_running;
  84. + unsigned long one_min_ptr = 0, five_min_ptr = 0, fifteen_min_ptr = 0;
  85. + unsigned long sum1 = 0, sum5 = 0, sum15 = 0;
  86. + unsigned char one_min[SAMPS_PER_MIN];
  87. + unsigned char five_min[SAMPS_PER_5MIN];
  88. + unsigned char fifteen_min[SAMPS_PER_15MIN];
  89.   void
  90.   DUMPPROC()
  91.   {
  92. ***************
  93. *** 648,653 ****
  94. --- 660,670 ----
  95.   #ifdef DEBUG_INFO
  96.       PROC *p = curproc;
  97.   
  98. +     FORCE("Uptime: %ld seconds Loads: %ld %ld %ld Processes running: %ld",
  99. +         uptime,
  100. +         (avenrun[0]*100)/2048 , (avenrun[1]*100)/2048, (avenrun[2]*100/2048),
  101. +          number_running);
  102.       for (curproc = proclist; curproc; curproc = curproc->gl_next) {
  103.           FORCE("state %s PC: %lx BP: %lx",
  104.           qname(curproc->wait_q),
  105. ***************
  106. *** 656,659 ****
  107. --- 673,739 ----
  108.       }
  109.       curproc = p;        /* restore the real curproc */
  110.   #endif
  111. + }
  112. + unsigned long gen_average(sum, cur_load, load_array, ptr, max_size)
  113. + long *sum;
  114. + unsigned long cur_load;
  115. + unsigned char load_array[];
  116. + unsigned long ptr;
  117. + int max_size;
  118. + {
  119. +     unsigned long retval;
  120. +     long old_load, new_load;
  121. +     old_load = (long)load_array[ptr];
  122. +     new_load = (long)cur_load;
  123. +     load_array[ptr] = (char)new_load; 
  124. +     *sum += ((new_load - old_load) * LOAD_SCALE);
  125. +     retval = (unsigned long)(*sum / max_size);
  126. +     return retval;
  127. + }
  128. + void calc_load_average()
  129. + {
  130. +     if (tick < TICKS_PER_TOCK)
  131. +         tick++;
  132. +     else
  133. +     {
  134. +         PROC *p;
  135. +         uptime++;
  136. +         tick = 0;
  137. +         if (uptime % 5) return;
  138. +         number_running = 0;
  139. +     
  140. +         for (p = proclist; p; p = p->gl_next)
  141. +             if (p != rootproc)
  142. +                 if ((p->wait_q == 0) || (p->wait_q == 1))
  143. +                     number_running++;
  144. +         avenrun[0] = gen_average(&sum1, number_running,
  145. +             one_min, one_min_ptr++, SAMPS_PER_MIN);
  146. +         if (one_min_ptr == SAMPS_PER_MIN)
  147. +             one_min_ptr = 0;
  148. +         avenrun[1] = gen_average(&sum5, number_running,
  149. +             five_min, five_min_ptr++, SAMPS_PER_5MIN);
  150. +         if (five_min_ptr == SAMPS_PER_5MIN)
  151. +             five_min_ptr = 0;
  152. +         avenrun[2] = gen_average(&sum15, number_running,
  153. +             fifteen_min, fifteen_min_ptr++, SAMPS_PER_15MIN);
  154. +         if (fifteen_min_ptr == SAMPS_PER_15MIN)
  155. +             fifteen_min_ptr = 0;
  156. +     }
  157.   }
  158. --8<-- Cut -- Here --8<--
  159.  
  160. -- 
  161. ---------------------------------------------------------------------------
  162. Computer Systems Administrator, Dept. of Earth Sciences, Oxford University.
  163. E-Mail: steve@uk.ac.ox.earth (JANET) steve@earth.ox.ac.uk (Internet).
  164. Tel:- Oxford (0865) 282110 (UK) or +44 865 282110 (International).
  165.